import { getTenantID, onMouseOutBtn } from '@/utils';
import { Button, Form, InputNumber, Select } from 'antd';
import Cls from 'classnames';
import { FormInstance } from 'antd/es/form/Form';
import { DeleteOutlined } from '@ant-design/icons';
import { ILoadMapTypeAll } from '@/common';
/**
 * @getExtractModalColumns 步骤条第二步 弹窗配置
 */
// export const getExtractTableConfig = (uploadForm: any): Record<string, any>[] => {
//   /**保存上级岗位搜索输入框的值*/
//   const [treeSearch, setTreeSearch] = useState<string>('');

//   const loadMdicIds: string[] = [`${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`];
//   const { loadMapInfo: loadMdicMapList, mapLoading } = getLoadMapList(loadMdicIds);

//   return [
//     {
//       title: '专家类型',
//       dataIndex: 'expertTypeName',
//       key: 'expertTypeName',
//       visible: true,
//       width: 180,
//       sorter: (a: any, b: any) => (a?.expertType > b?.expertType ? 1 : -1),
//       render: (_text: string, _record: any, index: any) => {
//         return (
//           <Form.Item
//             name={['extractTable', index, 'expertType']}
//             rules={[
//               {
//                 required: true,
//                 message: '请选择专家类型',
//               },
//             ]}
//           >
//             {loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`]?.map((item: any) => {
//               return (
//                 <Select.Option key={item?.id} value={item?.id}>
//                   {item?.name}
//                 </Select.Option>
//               );
//             })}
//           </Form.Item>
//         );
//       },
//     },
//   ];
// };

/** 抽取专家 new */
export const getExtractTableConfig = (
  addMaterialCallback: () => void,
  delMaterialCallback: (resObj: Record<string, any>) => void,
  formName: FormInstance,
  loadMapInfo: Record<string, any>,
  mapLoading: boolean,
  unitList: Array<Record<string, any>>,
): Record<string, any>[] => {
  /** 人数变化时 */
  const countChange = (value: any, index: number) => {
    handleMaterialCombined(formName, index, value, 'count');
  };

  /** 处理数据 */
  const handleMaterialCombined = (formData: FormInstance, fomIndex: number, currentValue: any, formType: string) => {
    const materialFormValues: Record<string, any>[] = formData?.getFieldValue('extractTable');

    if (formType == 'count') {
      materialFormValues[fomIndex]['count'] = currentValue;
    }

    formData?.setFieldsValue({
      extractTable: materialFormValues,
    });
  };

  const tableConfig: Record<string, any>[] = [
    {
      title: <div style={{ textAlign: 'center' }}>专家类型</div>,
      dataIndex: 'expertType',
      key: 'expertType',
      visible: true,
      width: 80,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'expertType']} rules={[{ required: true, message: '请选择专家类型' }]}>
            <Select placeholder="请选择专家类型" loading={mapLoading}>
              {loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`]?.map((item: any) => {
                return (
                  <Select.Option key={item?.id} value={item?.id}>
                    {item?.name}
                  </Select.Option>
                );
              })}
            </Select>
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>人数</div>,
      dataIndex: 'count',
      key: 'count',
      visible: true,
      width: 80,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'count']} rules={[{ required: true, message: '请输入人数' }]}>
            <InputNumber
              placeholder="请输入"
              // onChange={(value: any) => {
              //   countChange(value, index);
              // }}
              min={1}
            />
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>屏蔽单位</div>,
      dataIndex: 'companyNames',
      key: 'companyNames',
      visible: true,
      width: 150,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'companyNames']}>
            <Select mode="multiple" allowClear style={{ width: '100%' }} placeholder="选择屏蔽单位" options={unitList} />
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>操作</div>,
      dataIndex: 'otherBtn',
      key: 'otherBtn',
      visible: true,
      width: 50,
      render: (_text: string, _record: any, index: any) => {
        return (
          <div className="counterpoartDelBtnStyle">
            <Button
              type="link"
              icon={<DeleteOutlined />}
              className={Cls('manageBtntTxtStyle')}
              onMouseOut={onMouseOutBtn}
              onClick={() => {
                delMaterialCallback(_record);
              }}
            >
              清除
            </Button>
          </div>
        );
      },
    },
  ];

  // tableConfig?.push({
  //   title: (
  //     <div style={{ width: '100%', textAlign: 'center' }}>
  //       <Button
  //         type="link"
  //         icon={<PlusCircleOutlined />}
  //         className="manageBtntTxtStyle"
  //         onClick={addMaterialCallback}
  //         onMouseOut={onMouseOutBtn}
  //       >
  //         添加
  //       </Button>
  //     </div>
  //   ),
  //   dataIndex: 'otherBtn',
  //   key: 'otherBtn',
  //   width: 50,
  //   render: (_text: any, record: any) => {
  //     return (
  //       <div className="counterpoartDelBtnStyle">
  //         <Button
  //           type="link"
  //           icon={<DeleteOutlined />}
  //           className={Cls('manageBtntTxtStyle')}
  //           onMouseOut={onMouseOutBtn}
  //           onClick={() => {
  //             delMaterialCallback(record);
  //           }}
  //         >
  //           清除
  //         </Button>
  //       </div>
  //     );
  //   },
  // });

  return tableConfig;
};
